﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Web;

namespace System.Web.Mvc
{
    /// <summary>
    /// 扩展类
    /// </summary>
    public static class Extentions
    {
        public static string ScriptOrCss(this UrlHelper helper, string value)
        {
            string jsCssVersion = ConfigurationManager.AppSettings["js_css_version"];
            if (string.IsNullOrEmpty(jsCssVersion))
            {
                return helper.Content(value);
            }
            return helper.Content(string.Format(value + "?_v={0}", jsCssVersion));
        }
        public static string ToMB(this double num)
        {
            String[] units = new String[] { "B", "KB", "MB", "GB", "TB", "PB" };
            double mod = 1024.0;
            int i = 0;
            while (num >= mod)
            {
                num /= mod;
                i++;
            }
            return Math.Round(num) + units[i];
        }
    }
}